﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Web;

using JSIF_WCFServer.Model;
using System.IO;

namespace JSIF_WCFServer.Server
{
    /// <summary>
    /// A service which allows a user to do server level book management
    /// </summary>
    [ServiceContract(SessionMode = SessionMode.Allowed)]
    public interface IBookshelfManager
    {
        /// <summary>
        /// Returns the source code and published files for the specified book packaged into an archive
        /// </summary>
        /// <param name="shortname">The server specific shortname of the book</param>
        /// <returns>the source code and published files for the specified book packaged into an archive</returns>
        [WebInvoke(UriTemplate = "/books/{shortname}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, Method = "GET")]
        [OperationContract]
        Stream ExportStory(String shortname);

        /// <summary>
        /// Imports a premade archive containing the source code (optional) and published files (required) and gives it the specified server specific shortname.  Can also import Z-Code files and Glux files.
        /// </summary>
        /// <remarks>
        /// This method can also be used to overwrite an existing book.  Once upload is complete you should make a second call to set the meta data.
        /// </remarks>
        /// <param name="shortname">The server specific shortname of the book</param>
        /// <param name="uploadedFile">An archive</param>
        /// <returns>true if the operation completed sucessfully</returns>
        [WebInvoke(UriTemplate = "/books/{shortname}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, Method = "POST")]
        [OperationContract]
        bool ImportStory(String shortname, Stream uploadedFile);

        /// <summary>
        /// Deletes the specified book from the bookshelf
        /// </summary>
        /// <param name="shortname">The server specific shortname of the book</param>
        /// <returns>true if the operation completed sucessfully</returns>
        [WebInvoke(UriTemplate = "/books/{shortname}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, Method = "DELETE")]
        [OperationContract]
        bool DeleteStory(String shortname);

        /// <summary>
        /// Copies a whole book including history from shortnameA to shortnameB
        /// </summary>
        /// <remarks>
        /// This can also be used to overwrite the book at shortnameB
        /// </remarks>
        /// <param name="shortnameA">The source book</param>
        /// <param name="shortnameB">The destination book</param>
        /// <returns>true if the operation completed sucessfully</returns>
        [WebInvoke(UriTemplate = "/books-copy/{shortnameA}/{shortnameB}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, Method = "POST")]
        [OperationContract]
        bool CopyStory(String shortnameA, String shortnameB);

        /// <summary>
        /// Copies A to B, then deletes A
        /// </summary>
        /// <remarks>
        /// This can also be used to overwrite the book at shortnameB
        /// </remarks>
        /// <param name="shortnameA">The books original name</param>
        /// <param name="shortnameB">The books new name</param>
        /// <returns>true if the operation completed sucessfully</returns>
        [WebInvoke(UriTemplate = "/books-rename/{shortnameA}/{shortnameB}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, Method = "POST")]
        [OperationContract]
        bool RenameStory(String shortnameA, String shortnameB);


    }
}
